package Top200;

/**
 * @author zhangmin
 * @create 2022-02-26 11:36
 */
public class search81 {
    public boolean search(int[] nums, int target) {
        if (nums.length==0) return false;
        if (nums.length==1) return nums[0]==target;
        int left=0,right=nums.length-1;
        while (left<=right){
            int mid=left+(right-left)/2;
            if (nums[mid]==target){
                return true;
            }
            if (nums[left]==nums[mid]&&nums[mid]==nums[right]){
                left++;right--;
            } else if (nums[mid]<=nums[right]){
                if (nums[mid]<target&&target<=nums[right]){
                    left=mid+1;
                }else {
                    right=mid-1;
                }
            }else {
                if (nums[left]<=target&&target<nums[mid]){
                    right=mid-1;
                }else {
                    left=mid+1;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        int[] nums= {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1};
        search81 obj=new search81();
        System.out.println(obj.search(nums,2));
    }
}
